/*	This program produces Table D.7 */

***** Set directories 
local dir_clean 	"~/Dropbox/Retirement gaming/clean"
local dir_output 	"~/Dropbox/Retirement gaming/output/dataverse"


use "`dir_clean'/ech_clean.dta", clear

local listcontrols = " i.t i.fsize i.ciiu2  i.year#i.fsize i.year#i.ciiu2   " 


reghdfe W age_centered if (empl==1 & small==1 ) [aw=weight], absorb(`listcontrols') vce(robust)
g sample_emplsmall=e(sample)


** UNDERREPORTING BY FIRM SIZE 
* Panel A
estimates clear
foreach s in 1 0 {
		preserve
		keep if sample_emplsmall==`s' & year>=2006 //  
		*Normalize underrep
		sum underrep if age_centered==-1
		local meanu=r(mean)
		g underrepz=underrep/`meanu'
		* Regress
		eststo: reghdfe underrep pre48 post5053 post54 [aw=weight], absorb(`listcontrols') vce(robust) 
		restore
}
* Table with results 
esttab using "`dir_output'/tableD7a.tex", ///
	keep(pre* post* )  noobs sfmt(%9.0f) ///
	b(%4.3f) se(%4.3f) star(* 0.10 ** 0.05 *** 0.01) ///
	f nomtitles  nogaps replace label nonumbers nolines

* Panel B
estimates clear
foreach s in 1 0 {
		preserve
		keep if sample_emplsmall==`s'  & year>=2006 //  
		*Normalize underrep
		sum underrep if age_centered==-1
		local meanu=r(mean)
		g underrepz=underrep/`meanu'
		* Regress
		eststo: reghdfe underrep aget post50 aget_post50 [aw=weight], absorb(`listcontrols') vce(robust) 
		estadd scalar bmean=`meanu'
		restore
}	
* Table with results 
esttab using "`dir_output'/tableD7b.tex", ///
	keep(post* age*) stats(N bmean, label("Observations" "Baseline Mean") fmt(%9.0gc %9.2f)) ///
	b(%4.3f) se(%4.3f) star(* 0.10 ** 0.05 *** 0.01) ///
	f nomtitles  nogaps replace label nonumbers nolines prefoot(\hline) 
